package fhp.hlhj.giantfold.activity.user

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import android.support.v4.view.ViewPager
import com.mob.tools.gui.ViewPagerAdapter
import fhp.hlhj.giantfold.BaseActivity
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.activity.orders.TiketAty
import fhp.hlhj.giantfold.adapter.ViewPagerAdp
import fhp.hlhj.giantfold.customView.OrderPop
import fhp.hlhj.giantfold.fragment.OrderFgm
import kotlinx.android.synthetic.main.activity_order_aty.*

class OrderAty : BaseActivity(), ViewPager.OnPageChangeListener, TabLayout.OnTabSelectedListener, OrderPop.onPopSelect {

    private lateinit var orderPop:OrderPop
    private var fragments=ArrayList<Fragment>()
    private lateinit var allFgm:OrderFgm
    private lateinit var goingFgm:OrderFgm
    private lateinit var savedFgm:OrderFgm
    private lateinit var uselessFgm:OrderFgm
    private lateinit var toFlipFgm:OrderFgm
    private lateinit var pagerAdp: ViewPagerAdp
    override fun getContentId(): Int = R.layout.activity_order_aty
    override fun initView() {
        orderPop=OrderPop(this,this)
        allFgm= OrderFgm.newInstece("全部")
        goingFgm= OrderFgm.newInstece("进行中")
        savedFgm= OrderFgm.newInstece("已存入")
        uselessFgm=OrderFgm.newInstece("已失效")
        toFlipFgm= OrderFgm.newInstece("待翻牌")

        fragments.add(allFgm)
        fragments.add(goingFgm)
        fragments.add(savedFgm)
        fragments.add(uselessFgm)
        fragments.add(toFlipFgm)

        pagerAdp= ViewPagerAdp(supportFragmentManager,fragments)

        viewPager.adapter=pagerAdp
    }

    override fun initListener() {
        viewPager.addOnPageChangeListener(this)
        tabLayout.addOnTabSelectedListener(this)

        btChooseType.setOnClickListener {
            if (orderPop.isShowing){
                orderPop.dismiss()
            }else{
                orderPop.showAsDropDown(btChooseType)

            }
        }
        btExit.setOnClickListener {
            finish()
        }

    }

    override fun onPageScrollStateChanged(state: Int) {
    }

    override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
    }

    override fun onPageSelected(position: Int) {
        tabLayout.getTabAt(position)?.select()
    }

    override fun onTabReselected(tab: TabLayout.Tab?) {
    }

    override fun onTabUnselected(tab: TabLayout.Tab?) {
    }

    override fun onTabSelected(tab: TabLayout.Tab?) {
        val position = tab?.position
        if (position != null) {
            viewPager.currentItem = position
        }
    }

    /*点击事件回调*/
    override fun jzOrder() {

    }

    override fun aliOrder() {
        this.startActivity(android.content.Intent(this,fhp.hlhj.giantfold.activity.malls.TBOrderListAty::class.java))
    }

    override fun jdOrder() {
        this.startActivity(android.content.Intent(this,fhp.hlhj.giantfold.activity.malls.JdOrderListAty::class.java))

    }

    override fun xpOrder() {
        this.startActivity(android.content.Intent(this, TiketAty::class.java))
    }
}
